package smedi.ismedi.web.bff.controller.dangeroussource;

import com.smedi.ismedi.dangeroussourcemanage.api.dto.request.DangerousSourceManageRequest;
import com.smedi.ismedi.dangeroussourcemanage.api.dto.request.QueryDangerousSourceLibraryListRequest;
import com.smedi.ismedi.dangeroussourcemanage.api.dto.request.QueryDangerousSourceLibraryPageListRequest;
import com.smedi.ismedi.dangeroussourcemanage.api.dto.request.QueryDangerousSourcePageListRequest;
import com.smedi.ismedi.dangeroussourcemanage.api.dto.response.DangerousSourceDetailResponse;
import com.smedi.ismedi.dangeroussourcemanage.api.dto.response.QueryDangerousSourceLibraryResponse;
import com.smedi.ismedi.dangeroussourcemanage.api.dto.response.QueryDangerousSourceListResponse;
import com.smedi.ismedi.dangeroussourcemanage.api.feign.RemoteDangerousSourceManageFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * 危险源
 *
 * @author xuyuanqiao
 * @date 2021/09/02
 */
@Slf4j
@Api(value = "危险源管理接口", tags = {"危险源管理接口"})
@RequestMapping(value = "/webbff/v1/dangerousSourceManage")
@RestController
@AllArgsConstructor
public class DangerousSourceManageController {
    private final RemoteDangerousSourceManageFeignApi remoteDangerousSourceManageFeignApi;

    /**
     * 根据id查询危险源详情
     *
     * @param dangerousSourceId 需要查询的危险源id
     * @return ResponseData<DangerousSourceDetailResponse>
     */
    @ApiOperation(httpMethod = "GET", value = "根据id查询危险源详情")
    @GetMapping(value = "/detail")
    ResponseData<DangerousSourceDetailResponse> getDangerousSourceDetail(@RequestParam(value = "dangerousSourceId") Long dangerousSourceId){
        return remoteDangerousSourceManageFeignApi.getDangerousSourceDetail(dangerousSourceId);
    }

    /**
     * 新增或修改危险源
     *
     * @param dangerousSourceManageRequest 新增或修改危险源请求
     * @return ResponseData<Long>
     */
    @ApiOperation(httpMethod = "POST", value = "新增或修改危险源")
    @PostMapping(value = "/add")
    ResponseData<Long> postAddDangerousSource(@Validated @RequestBody DangerousSourceManageRequest dangerousSourceManageRequest)
    {
        return remoteDangerousSourceManageFeignApi.postAddDangerousSource(dangerousSourceManageRequest);
    }

    /**
     * 根据id集合删除危险源
     *
     * @param dangerousSourceIds 需要删除的危险源id集合
     * @return ResponseData<Long>
     */
    @ApiOperation(httpMethod = "DELETE", value = "根据id集合删除危险源")
    @DeleteMapping(value = "/delete")
    ResponseData<Long> getDeleteDangerousSource(@Validated @RequestBody List<Long> dangerousSourceIds){
        return remoteDangerousSourceManageFeignApi.getDeleteDangerousSource(dangerousSourceIds);
    }

    /**
     * 分页查询危险源列表
     *
     * @param dangerousSourcePageListRequest 分页查询危险源请求
     * @return PaginationData<QueryDangerousSourceListResponse>
     */
    @ApiOperation(httpMethod = "POST", value = "分页查询危险源列表")
    @PostMapping(value = "/pageList")
    ResponseData<PaginationData<QueryDangerousSourceListResponse>> postQueryDangerousSourceManagePageList(@Validated @RequestBody QueryDangerousSourcePageListRequest dangerousSourcePageListRequest){
        return remoteDangerousSourceManageFeignApi.postQueryDangerousSourceManagePageList(dangerousSourcePageListRequest);
    }

    /**
     * 分页查询危险源库列表
     *
     * @param queryDangerousSourceLibraryPageListRequest 分页查询危险源危库请求
     * @return ResponseData<Page < QueryDangerousSourceLibraryResponse>>
     */
    @ApiOperation(httpMethod = "POST", value = "分页查询危险源库列表")
    @PostMapping(value = "/libraryPageList")
    ResponseData<PaginationData<QueryDangerousSourceLibraryResponse>> postQueryDangerousSourceLibraryPageList(@Validated @RequestBody QueryDangerousSourceLibraryPageListRequest queryDangerousSourceLibraryPageListRequest){
        return remoteDangerousSourceManageFeignApi.postQueryDangerousSourceLibraryPageList(queryDangerousSourceLibraryPageListRequest);
    }

    /**
     * 查询危险源库列表(不分页)
     *
     * @param queryDangerousSourceLibraryListRequest 查询危险源危库请求
     * @return ResponseData<List < QueryDangerousSourceLibraryResponse>>
     */
    @ApiOperation(httpMethod = "POST", value = "查询危险源库列表(不分页)")
    @PostMapping(value = "/libraryList")
    ResponseData<List<QueryDangerousSourceLibraryResponse>> postQueryDangerousSourceLibraryList(@Validated @RequestBody QueryDangerousSourceLibraryListRequest queryDangerousSourceLibraryListRequest){
        return remoteDangerousSourceManageFeignApi.postQueryDangerousSourceLibraryList(queryDangerousSourceLibraryListRequest);
    }

    /**
     * 导出危险源列表
     *
     * @param dangerousSourceIds 危险源id集合
     * @return
     * @throws IOException
     */
    @ApiOperation(httpMethod = "POST", value = "导出危大列表")
    @PostMapping(value = "/exportList")
    ResponseEntity<byte[]> exportList(@Validated @RequestBody List<Long> dangerousSourceIds) throws IOException{
        return remoteDangerousSourceManageFeignApi.exportList(dangerousSourceIds);
    }
}
